<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;


use App\CustHub\Model\ChRoomActiveRoom;
use Hyperf\Database\Model\Collection;
use Mine\Abstracts\AbstractMapper;

class ChRoomActiveRoomMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChRoomActiveRoom::class;
    }

    public function findBySchemeIdAndType(int $schemeId,int $type): array|Collection
    {
        return $this->model::query()
            ->where('scheme_id',$schemeId)
            ->where('type',$type)
            ->get();
    }

    public function findByRoomWxidsAndType(int $mainUid,array $roomWxids, int $type): array|Collection|\Hyperf\Collection\Collection
    {
        return $this->model::query()
            ->where('main_uid',$mainUid)
            ->whereIn('room_wxid', $roomWxids)
            ->where('type', $type)->get();
    }


    public function findByRobotIdAndRoomWxid(int $robotId,string $roomWxid,int $type): array|Collection
    {
        return $this->model::query()
            ->where('robot_id',$robotId)
            ->when(!empty($roomWxid),function ($query) use ($roomWxid){
                $query->where('room_wxid',$roomWxid);
            })
            ->where('type',$type)
            ->get();
    }

}